/*
 * Copyright (C) 2009 Leandro Aparecido <lehphyro@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.metalframework.persistence.annotation;

import java.lang.annotation.*;

/**
 * Marks a collection or single object to be filled/replaced with the return value of a JPA query.
 * 
 * @since 1.0
 * @see org.metalframework.persistence.annotation.FetchStrategy
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@Documented
public @interface RepositoryQuery {
	/**
	 * Equivalent to <code>name</code>, it is just for convenience when you need to set only
	 * the named query to be used.
	 * <p>Either this or <code>name</code> is required.
	 */
	String value() default "";
	
	/**
	 * Name of the JPA named-query.
	 * <p>Either this or <code>value</code> is required.
	 */
	String name() default "";

	/**
	 * Indicates if the JPA query parameters should be taken from the javabean-style properties
	 * of the annotated object.
	 * <p>Defaults to <code>false</code>.
	 */
	boolean byExample() default false;

	/**
	 * Argument names of the method if your classes have not been compiled in debug mode.
	 */
	String argNames() default "";

	/**
	 * Marks the collection as holder of the extent of the collection generic type (the JPA entity).
	 * <p>Defaults to <code>false</code>. <code>True</code> if the type of the element is
	 * {@link org.metalframework.persistence.Extent}.
	 */
	boolean extent() default false;

	/**
	 * Fetch strategy to be used when fetching entities from repository.
	 * <p>Defaults to {@link FetchStrategy#ALL}
	 */
	FetchStrategy fetch() default FetchStrategy.ALL;

	/**
	 * How many entities to fetch from database on each round-trip.
	 * Note that not all fetch strategies are required to support this parameter.
	 * <p>Defaults to zero.
	 */
	int fetchSize() default 0;
}
